<template>
   <div class="rankBox" :style="backgroundStyle">
    <div class="content">
      <div class="same-tr my-store">
        <div class="pm">本店</div>
        <div class="csmc">{{ placeRank.placeName }}</div>
        <div class="rank">第{{ placeRank.rank }}名</div>
        <div class="score">{{ placeRank.score }}分</div>
      </div>
      <div class="same-tr rank-head">
        <div class="pm">排名</div>
        <div class="csmc">场所名称</div>
        <div class="rank"></div>
        <div class="score">积分</div>
      </div>
      <van-list
        v-model="loading"
        @load="onLoad"
        style="border-radius: 12px;"
      >
        <van-cell v-for="(item,index) in list" :key="index">
          <div class="same-tr">
            <div class="pm">
              <img class="rank-icon" v-if="index == 0" :src="rank1" alt="" srcset="" />
              <img class="rank-icon" v-else-if="index == 1" :src="rank2" alt="" srcset="" />
              <img class="rank-icon" v-else-if="index == 2" :src="rank3" alt="" srcset="" />
              <span class="rank-index" v-else>{{ index + 1 }}</span>
            </div>
            <div class="csmc">{{ item.placeName }}</div>
            <div class="rank"></div>
            <div class="score">{{ item.score }}</div>
          </div>
        </van-cell>
      </van-list>
    </div>
  </div>
</template>

<script>
import { getPlaceRankByCode, getPlaceRankList } from '@/api/info';

let drp = window.localStorage.getItem('dpr');
export default {
  name: 'rank',
  data() {
    return {
      bgImg: 'url(' + require("@/images/rank_top_@" + drp + "x.png") + ')',
      rank1: require("@/images/top1_@" + drp + "x.png"),
      rank2: require("@/images/top2_@" + drp + "x.png"),
      rank3: require("@/images/top3_@" + drp + "x.png"),
      list: [
        { csmc: '金宝PARK天阶', score: 150 },
        { csmc: '金宝PARK天阶', score: 150 },
        { csmc: '金宝PARK天阶', score: 150 },
        { csmc: '金宝PARK天阶', score: 150 },
        { csmc: '金宝PARK天阶', score: 150 },
        { csmc: '金宝PARK天阶', score: 150 },
        { csmc: '金宝PARK天阶', score: 150 },
        { csmc: '金宝PARK天阶', score: 150 },
        { csmc: '金宝PARK天阶', score: 150 },
        { csmc: '金宝PARK天阶', score: 150 }
      ],
      loading: false,
      error: true,
      activeName: 'redb',
      params: {
        pageNum: 1,
        pageSize: 10,
      },
      total: null,
      placeRank: {}
    }
  },
  created() {
    if(this.$route.query.id) {
      this.getPlaceRankByCode(this.$route.query.id);
      this.getPlaceRankList()
    }
  },
  computed: {
    backgroundStyle() {
      return {
        backgroundImage: this.bgImg
      }
    },
  },
  methods: {
    onLoad() {
      /* fetchSomeThing().catch(() => {
        this.error = true;
      }); */
    },
    // 获取自身排名
    getPlaceRankByCode(placeCode) {
      getPlaceRankByCode(placeCode).then(res => {
        if(res.code == 200) {
          this.placeRank = res.data;
        }
      })
    },
    // 排行榜列表
    getPlaceRankList() {
      getPlaceRankList(this.params).then(res => {
        if(res.code == 200) {
          this.list = res.rows;
          this.total= res.total;
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.rankBox {
  background-size: 100% 160px;
  background-repeat: no-repeat;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  background-position: top center;
  background-color: #F8F8F8;
  .content {
    margin: 14px 16px;
    box-sizing: border-box;
    margin-top: 120px;
    background-color: #fff;
    border-radius: 12px;
    padding: 16px 12px;
    .same-tr {
      display: flex;
      width: 100%;
      font-size: 12px;
      padding: 12px;
      box-sizing: border-box;
      font-weight: 600;
      align-items: center;
      .pm {
        width: 15%;
        text-align: left;
        .rank-icon {
          display: block;
          width: 30px;
          margin: 0 auto;
        }
        .rank-index {
          padding-left: 20px;
        }
      }
      .csmc {
        width: 55%;
        text-align: left;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }
      .rank {
        width: 15%;
      }
      .score {
        width: 15%;
        text-align: right;
      }
      &.rank-head {
        color: #999999;
        font-weight: normal;
      }
      &.my-store {
        background-color: #e891071f;
        border-radius: 6px;
        .pm, .rank, .score {
          color: #FF8F1F;
        }
      }
    }
    /deep/ .van-cell {
      padding: 10px 0;
      .same-tr {
        padding: 0;
        .score {
          padding-right: 16px;
        }
      }
    }
  }
}
</style>